#include <iostream>
using namespace std;
void swap1 (int *a ,int *b, int c = 1);


void swap2 (int &a ,int &b)
{// 传入引用，也可以改变被引用的数值a与b
    int tmp = a;
    a = b;
    b = tmp;
}



int main ()
{
    int i = 10;
    int &ir = i;
    cout << ir << endl;
    cout << &i << endl;
    cout << &ir << endl;
//0x7ffe61ba78ac
//0x7ffe61ba78ac
// 引用与本体的内存地址相同

    int x =10;
    int y =20;
    swap1(&x , &y);
    cout << x << endl;
    cout << y << endl;

    swap2(x,y);
    cout << x << endl;
    cout << y << endl;

    return 0;
}

void swap1 (int *a ,int *b, int c)
{// 传入指针，可以改变内存地址对应的数值
    int tmp = *a;
    *a = *b;
    *b = tmp;
}
